package com.company.serialization;

import java.io.*;

/**
 * @description: java序列化机制
 * @author: ruoan
 * @date: 2021/1/3 12:00
 */
public class Test1 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {

        Student ss = new Student();
        ss.setUserName("章SAN");
        ss.setUserId(11);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(ss);
        //System.out.println(byteArrayOutputStream.toByteArray().getClass().getName());
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        Student st = (Student)objectInputStream.readObject();
        System.out.println(st.getUserId());
        System.out.println(st.getUserName());


    }
}
